package com.css.dbshards;

import org.apache.ibatis.session.SqlSession;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


/**
 * @author 郭辉
 * @className TODO
 * @description TODO
 * @date 2022/11/29 8:57
 * @company 海康威视
 * @since 1.0.0
 */
@RestController
@RequestMapping("/dbshards")
public class DbShardscontroller {
    @RequestMapping("/save")
    public String save() {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        DbShardMapper mapper = sqlSession.getMapper(DbShardMapper.class);
        Integer integer = mapper.insertOne(new DbShardsEntity("8778f843c5cec712be47430c8916d2ad", "10000", "9bb45e1deac9f925ce1358d1ddb7fdd7", "我是db_father10000子表"));
        System.out.println(integer);
//        mapper.insertOne(new DbShardsEntity("929d8025664959b7f02774314ce69e6a", "20000", "19855c4edde6c6a1e25a63f0eadbe28f", "我是db_father20000子表"));
//        mapper.insertOne(new DbShardsEntity("c85a1130d53d87921287f5b8b8c8c6c8", "30000", "1256e6a48fbc0db393adc6cd1960ef44", "我是db_father30000子表"));
//        mapper.insertOne(new DbShardsEntity("9a8b01388f5fa3816e984f51cf62373f", "40000", "60ae95b6e2fbc62bddc48a3537a06a82", "我是db_father40000子表"));
//        mapper.insertOne(new DbShardsEntity("51fde34cb00be6cbb17061ada8d1fa52", "50000", "4411e6eaf94cd60443606cb44377ba10", "我是没有子表的数据"));
        return "Productor - nacos";
    }

    @RequestMapping("/createChildTable")
    public String createChildTable() {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        DbShardMapper mapper = sqlSession.getMapper(DbShardMapper.class);
        Integer integer = mapper.createTable("db_father_1000");
        System.out.println(integer);
        return "Productor - nacos";
    }

    @RequestMapping("/ping")
    public String ping(@RequestBody Map<Object,Object> map) {
       /* SqlSession sqlSession = MybatisUtils.getSqlSession();
        DbShardMapper mapper = sqlSession.getMapper(DbShardMapper.class);
        Integer integer = mapper.createTable("db_father_1000");*/

        Integer integer = (Integer)map.get("count")+1;
        System.out.println(integer);
        return "pong";
    }
}
